﻿#region Copyright
//Copyright 2012 Phelon Aka. Jon H.
/*
    This file is part of BGBuddy - Ultimate PVP Suite.

    BGBuddy - Ultimate PVP Suite is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    BGBuddy - Ultimate PVP Suite is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>
 */
#endregion

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Styx;
using Styx.Helpers;
using Styx.WoWInternals;
using Styx.CommonBot;
using Styx.MemoryManagement;
using Styx.TreeSharp;
using Styx.Pathing;
using Styx.Plugins;
using Styx.WoWInternals.WoWObjects;

namespace UltimatePvPSuite
{
    public class UltimatePvPSuite : HBPlugin
    {
        #region Constants
        public override string Name { get { return "* Ultimate PVP Suite * Version: " + Version; } }
        public override string Author { get { return "Phelon"; } }
        public override Version Version { get { return new Version(1, 18); } }
        public static bool FlagExists = false;
        public static bool PowerUpExists = false;
        public static bool InsigniaExists = false;
        public static WoWUnit CurrentTarget = StyxWoW.Me;
        private static bool Friends = false;
        public static WoWPoint InitialFlagLocation;
        public static WoWPlayer CurrentTargetPlayer;
        public static string CurrentTargetType;
        public static List<string> InterruptSpells = new List<string>();
        private static bool RunOnce = false;
        #endregion

        #region Variables
            #region General Settings

            #region Targeting Options
            public static bool EnabledPriorityTargeting;
            public static bool EnabledForceCombat;
            public static bool EnableTargetingLoSLogic;
            public static int TargetCheckFrequency;
            #endregion

            #region PVP and Racials
            public static bool EnablePvPTrinket;
            public static bool EnableRacialTraits;
            #endregion

            #region Banners and Flags
            public static bool EnableBannerCap;
            public static bool EnableReturnFlag;
            #endregion

            #region Refreshments and Soul Wells
            public static bool EnableUseRefreshments;
            public static bool EnableCreateRefreshments;
            public static bool EnableUseSoulwell;
            public static bool EnableCreateSoulwell;
            #endregion

            #region Interrupts
            public static bool EnableInterrupts;
            public static bool EnableInterruptEveryone;
            public static bool EnableFirstInterrupt;
            public static string FirstInterruptSpell;
            public static string FirstSpellRange;
            public static bool EnableSecondInterrupt;
            public static string SecondInterruptSpell;
            public static string SecondSpellRange;
            public static bool EnableThirdInterrupt;
            public static string ThirdInterruptSpell;
            public static string ThirdSpellRange;
            #endregion

            #region Consumables
            public static bool EnableUseHealthStone;
            public static bool EnableUseHealthPotions;
            public static bool EnableUsePvPHealthPotions;
            public static bool EnableUsePvPBanner;
            public static bool EnableUseHealthTrinket;
            public static string UseConsumablePercent;
            #endregion

            #region Loot Insignia's
            public static bool EnableLootInsignia;
            public static string LootInsigniaRange;
            #endregion

            #region Get BG Power Ups
            public static bool EnableGetBGPowerUps;
            public static string GetBGPowerUpsRange;
            #endregion

            #region Strafe Logic
            public static bool EnableStrafing;
            public static bool StayBehindTarget;
            public static bool EnableJump;
            public static bool DisabledCCMovement;
            public static string StrafeDistance;
            public static bool StrafeAwayFromTarget;
            public static bool StrafeOnlyOnCC;
            public static bool StayNearGroup;
            public static string CastTargetRange;
            public static string GroupSearchRange;
            #endregion

            #region Pulse Frequency
            public static int HonorbuddyTPS;
            #endregion

            #endregion

            #region Targeting

            #region Demolishers
            public static bool EnableTargetDemolishers;
            public static int TargetDemolishersRange;
            public static string TargetDemolishersPriority;
            #endregion

            #region Flag Carriers
            public static bool EnableTargetFlagCarriers;
            public static int TargetFlagCarriersRange;
            public static string TargetFlagCarriersPriority;
            #endregion

            #region Healers
            public static bool EnableTargetHealers;
            public static int TargetHealersRange;
            public static string TargetHealersPriority;
            #endregion

            #region Low Health
            public static bool EnableTargetLowHealth;
            public static int TargetLowHealthRange;
            public static string TargetLowHealthPriority;
            #endregion

            #region Undergeared
            public static bool EnableTargetUndergeared;
            public static int TargetUndergearedRange;
            public static string TargetUndergearedPriority;
            #endregion

            #region Totems
            public static bool EnableTargetTotems;
            public static int TargetTotemsRange;
            public static string TargetTotemsPriority;
            #endregion

            #endregion
        #endregion


        //Set the Varialbes for the Bot
        private static void SetNormalVariables()
        {             
            #region General Settings

            #region Targeting Options
            EnabledPriorityTargeting = true;
            EnabledForceCombat = false;
            EnableTargetingLoSLogic = false;
            TargetCheckFrequency = 10;
            #endregion

            #region PVP and Racials
            EnablePvPTrinket = true;
            EnableRacialTraits = true;
            #endregion

            #region Banners and Flags
            EnableBannerCap = false;
            EnableReturnFlag = false;
            #endregion

            #region Refreshments and Soul Wells
            EnableUseRefreshments = false;
            EnableCreateRefreshments = false;
            EnableUseSoulwell = false;
            EnableCreateSoulwell = false;
            #endregion

            #region Interrupts

            #region INTERRUPT SPELL ADD AREA
            InterruptSpells.Add("Heal");
            InterruptSpells.Add("Flash Heal");
            #endregion

            EnableInterrupts = false;
            EnableInterruptEveryone = false;
            EnableFirstInterrupt = false;
            FirstInterruptSpell = "";
            FirstSpellRange = "";
            EnableSecondInterrupt = false;
            SecondInterruptSpell = "";
            SecondSpellRange = "";
            EnableThirdInterrupt = false;
            ThirdInterruptSpell = "";
            ThirdSpellRange = "";
            #endregion

            #region Consumables
            EnableUseHealthStone = true;
            EnableUseHealthPotions = true;
            EnableUsePvPHealthPotions = true;
            EnableUsePvPBanner = true;
            EnableUseHealthTrinket = true;
            UseConsumablePercent = "40";
            #endregion

            #region Loot Insignia's
            EnableLootInsignia = false;
            LootInsigniaRange = "7";
            #endregion

            #region Get BG Power Ups
            EnableGetBGPowerUps = false;
            GetBGPowerUpsRange = "7";
            #endregion

            #region Strafe Logic
            EnableStrafing = true;
            StayBehindTarget = true;
            EnableJump = false;
            DisabledCCMovement = false;
            StrafeDistance = "4";
            StrafeAwayFromTarget = true;
            StrafeOnlyOnCC = true;
            StayNearGroup = true;
            CastTargetRange = "30";
            GroupSearchRange = "60";
            #endregion

            #region Pulse Frequency
            HonorbuddyTPS = 25;
            #endregion

            #endregion

            #region Targeting

            #region Demolishers
            EnableTargetDemolishers = false;
            TargetDemolishersRange = 15;
            TargetDemolishersPriority = "80";
            #endregion

            #region Flag Carriers
            EnableTargetFlagCarriers = true;
            TargetFlagCarriersRange = 45;
            TargetFlagCarriersPriority = "80";
            #endregion

            #region Healers
            EnableTargetHealers = true;
            TargetHealersRange = 45;
            TargetHealersPriority = "100";
            #endregion

            #region Low Health
            EnableTargetLowHealth = true;
            TargetLowHealthRange = 45;
            TargetLowHealthPriority = "60";
            #endregion

            #region Undergeared
            EnableTargetUndergeared = true;
            TargetUndergearedRange = 45;
            TargetUndergearedPriority = "40";
            #endregion

            #region Totems
            EnableTargetTotems = true;
            TargetTotemsRange = 45;
            TargetTotemsPriority = "100";
            #endregion

            #endregion
        }

        public override void Initialize()
        {
            // Create our forms and settings and init's
            //Settings.Instance.Load();
            SetNormalVariables();
            Utils.Write("Loaded Successfully!");
            Utils.Write("Please go to PhelonsPlugins.BlogSpot.com for latest Version of Ultimate PvP Suite.");
            Utils.Write("Check Out ProfilePacks.com for User Submitted Profiles / Plugins / Guides!");
            Utils.Write("Version: {0}", Version);
        }

        public override void Dispose()
        {
            TreeRoot.TicksPerSecond = (byte)15;
        }

        public override void Pulse()
        {
            using (StyxWoW.Memory.AcquireFrame())
            {
                if (BotManager.Current.Name.Equals("BGBuddy"))
                {
                    if (StyxWoW.IsInGame == false || StyxWoW.Me.IsValid == false) return;

                    //Get rid of Blacklist if BGBuddy went stupid
                    if (StyxWoW.Me.IsActuallyInCombat && Movement.MoveTo(StyxWoW.Me.CurrentTarget)) { Blacklist.Flush(); }

                    //Checks to make sure everything is firing when it should be.
                    if (!Battlegrounds.IsInsideBattleground) { Movement.StopMovement(true, true, true, true); return; }

                    //Picks up Food and Drink from Table
                    Refreshments.Pulse();

                    //Checks to see if target is near and will try to Force Combat
                    //if (TargetHelper.TargetExists()) { TargetHelper.GetInCombat(); return; }

                    //Stops Targeting etc when dead.
                    if (StyxWoW.Me.IsDead || StyxWoW.Me.HasAura("Preparation")) { Movement.StopMovement(true, true, true, true); StyxWoW.Me.ClearTarget(); return; }


                    //Will Target if Flag isn't present
                    if (TargetHelper.Pulse())
                    {
                        //Utils.Write("TargetHelper");
                    }
                    //Breaks Crowd Controls
                    if (RacialsAndTrinkets.Pulse())
                    {
                        //Utils.Write("RacialsAndTrinkets");
                        return;
                    }

                    //Use Consumables
                    if (Consumables.Pulse())
                    {
                        //Utils.Write("Consumables");
                        return;
                    }

                    //Returns Flags and Caps Banners
                    if (FlagActions.Pulse())
                    {
                        //Utils.Write("FlagActions");
                        return;
                    }


                    //Interrupts
                    if (Interrupts.Pulse())
                    {
                        return;
                    }
                    //Insignia Remover
                    //if (InsigniaRemover.Pulse()) return;

                    //Tries to get BG Buffs.
                    if (PvPBuffs.Pulse() && StyxWoW.Me.IsActuallyInCombat)
                    {
                        //Utils.Write("PvPBuffs");
                        return;
                    }

                    //Strafe Logic if someone has a CC that strafes
                    //StrafeLogic.Pulse();
                }
            }
        }
        
        public override string ButtonText
        {
            get
            {
                return "* Ultimate PVP Suite *";
            }
        }

        public override bool WantButton
        {
            get
            {
                return true;
            }
        }

        public override void OnButtonPress()
        {
            MessageBox.Show("Configuration Form is available for Donators Only!" + System.Environment.NewLine + System.Environment.NewLine + "To access the GUI, please go to PhelonsPlugins.Blogspot.com to make a Donation.");
        }
    }
}
